<template>
  <div>
    <el-container style="width: 100%;height: 100vh">
      <el-header style="background-color:#CEFDEA;">
        <div>
          <div class="title">
            {{ title }}
          </div>
          <div class="topRight">
            <el-avatar :src="accountStore.account.accountHead">{{ accountStore.account.accountName }}</el-avatar>
            <el-button type="warning" @click="logout" text>退出</el-button>
          </div>
        </div>
      </el-header>
      <el-container style="height: 90vh">
        <el-aside width="200px">
          <el-menu class="el-menu-vertical-demo" @open="handleOpen" @close="handleClose" router="router">
            <menu-tree :menu-list="menuList"></menu-tree>
          </el-menu>
        </el-aside>
        <el-main>
          <div style="width: 100%;height: 20px;margin-bottom: 10px;">
            <el-breadcrumb separator="/">
              <el-breadcrumb-item :to="item.path" v-for="item in breadList">{{ item.name }}</el-breadcrumb-item>
            </el-breadcrumb>
          </div>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script setup lang="ts">

import MenuTree from "@/components/MenuTree.vue";
import {onMounted, ref, watch} from "vue";
import {useAccountStore, useMenuListStore} from "@/stores/counter";
import router from "@/router";
import {ElNotification} from "element-plus";
import {useRoute} from "vue-router";
import {removeToken} from "@/util/TokenUtil";

const title = ref('mall-v3')

const handleOpen = (key: string, keyPath: string[]) => {
  // console.log(key, keyPath)
}
const handleClose = (key: string, keyPath: string[]) => {
  // console.log(key, keyPath)
}
let menuList = ref<any[]>([])

const getMenu = async () => {
  let menuListStore = useMenuListStore();
  menuList.value = menuListStore.menuList;

}
//用户信息
const accountStore = useAccountStore();
// 退出
const logout = () => {
  useAccountStore().clearAccount()
  useMenuListStore().clearMenuList();
  removeToken();
  router.push('/login');
  ElNotification.success("退出登录")
}

//面包屑
const breadList = ref<any[]>([])
const route = useRoute();
const getCurrentPath = () => {
  breadList.value = route.matched;
}
watch(route, (to, from) => {
  getCurrentPath()
})

onMounted(() => {
  getMenu()
  getCurrentPath()
})

</script>

<style scoped>
.topRight {
  float: right;
  margin: 13px;
}

.title {
  float: left;
  font-size: 36px;
  font-style: italic;
  color: #016fe9;
}
</style>
